package com.changyi.device.printer;

import android.content.Context;

import com.changyi.device.DeviceConstant;
import com.changyi.device.TestXin;

/**
 * Created by xin on 2021/3/17
 * desc: 打印类
 */
public class PrintManagerLib {

//    private static PrintManagerLib mPrintManager;
//    private Context mContext;
//    private Handler hander = new Handler();
//    private static PrinterInterface printer;

//    private PrintManagerLib(Context context,int printerType) {
//        mContext = context;
//    }
//
//    /**
//     * 获得打印对象
//     * @param context
//     * @param printerType
//     * @return
//     */
//    public static PrintManagerLib getInstance(Context context,int printerType) {
//
//        if (mPrintManager == null) {
//            synchronized (PrintManagerLib.class){
//                if (mPrintManager == null) {
//                    mPrintManager = new PrintManagerLib(context);
//                }
//            }
//        }
//        initPrinter(context,printerType);//接口多个实现类
//        return mPrintManager;
//    }

    public static PrinterInterface initPrinter(Context context, String printerTypeStr) {
         int printerType = deviceModelInit(printerTypeStr);
        PrinterInterface printer = LandiA8Printer.getInstance(context);//默认A8
        switch (printerType){
            case DeviceConstant.LANDI_A8:{
                printer = LandiA8Printer.getInstance(context);
            }
                break;
            case DeviceConstant.HISENSE_HI98:{
                printer = HisenseHi98Printer.getInstance(context);
            }
            break;
            case DeviceConstant.ZQ_M2:{
                printer = ZQM2Printer.getInstance(context);
            }
            break;
            case DeviceConstant.SUNMI_P2:{
                printer = SunmiP2Printer.getInstance(context);
            }
            break;
            case DeviceConstant.T2:{
                printer = T2Printer.getInstance(context);
            }
            break;
            default:
                printer = LandiA8Printer.getInstance(context);
        }
        return printer;
    }

    public static int deviceModelInit(String printerTypeStr) {
        int deviceMode =  DeviceConstant.LANDI_A8;
        if(printerTypeStr.contains("HI98")){
            deviceMode =DeviceConstant.HISENSE_HI98;
        }else if(printerTypeStr.contains("M2")){
            deviceMode =  DeviceConstant.ZQ_M2;
        }else if(printerTypeStr.contains("P2")){
            deviceMode =DeviceConstant.SUNMI_P2;
        }else if(printerTypeStr.contains("T2")){
            deviceMode =DeviceConstant.T2;
        }
        else{
            deviceMode =  DeviceConstant.LANDI_A8;
        }
        return deviceMode;
    }


}
